package com.training.controller;

import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;
import com.training.common.Analyst;
import com.training.common.model.*;
import com.training.common.model.Class;
import com.training.service.AnalystService;
import com.training.service.AnalystServiceImp;
import com.training.service.StudentService;
import com.training.service.StudentServiceImp;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AnalystController extends Controller {

    @Inject(AnalystServiceImp.class)
    private AnalystService analystService;

    @Inject(StudentServiceImp.class)
    private StudentService studentService;

    public void index(){
        long studentCount = Student.dao.getStudentCount();
        long classCount = Class.dao.getClassCount();
        long subjectCount = Subject.dao.getSubjectCount();
        long studentResultjinri = Result.dao.getStudentResulttodayCount();
        setAttr("studentCount",studentCount);
        setAttr("classCount",classCount);
        setAttr("subjectCount",subjectCount);
        setAttr("studentResultjinri",studentResultjinri);
        render("/views/analyst/index.html");
    }

    public void getAnalyst(){
        String trainids = getPara("trainids");
        String subjectid = getPara("subjectid");
        String studentid = getPara("studentid");
        Analyst analyst = analystService.getAnalyst(trainids,subjectid,studentid);
        renderJson(analyst);
    }

    public void getStudnetList(){
        Map<String,Object> dataMap = new HashMap<String,Object>();
        renderJson(dataMap);
        Page<Student> studentPage = studentService.getStudentPage(1,10000,null,null,null);
        List<Student> studentList = studentPage.getList();
        dataMap.put("code",0);
        dataMap.put("msg","success");
        List<Map<String,Object>> data = new ArrayList<Map<String,Object>>();
        Map<String,Object> map = null;
        for(Student student : studentList){
            map = new HashMap<String,Object>();
            map.put("name",student.getName());
            map.put("value",student.getId());
            data.add(map);
        }
        dataMap.put("data",data);
        renderJson(dataMap);
    }
}
